package com.example.rootwar.search;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


class Pair {
    int x;
    int y;

    public Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class Solution {

    Random random = new Random();

    int[][] nums = null;

    int m;

    int n;

    List<Pair> dui = new ArrayList<>();

    int[] res = new int[2];

    int i = 0;
    int y = 0;

    public Solution(int m, int n) {
        this.nums = new int[m][n];
        this.m = m;
        this.n = n;

    }

    public int[] flip() {

        i = random.nextInt(m);
        y = random.nextInt(n);
        while (containsiy(dui, i, y)) {
            i = random.nextInt(m);
            y = random.nextInt(n);
        }

        nums[i][y] = 1;

        res[0] = i;
        res[1] = y;

        dui.add(new Pair(i, y));
        return res;
    }

    private boolean containsiy(List<Pair> dui, int i, int y) {
        for (Pair pair : dui) {
            if (pair.y == y && pair.x == i) {
                return true;
            }
        }
        return false;
    }

    public void reset() {
        this.nums = new int[m][n];
        dui.clear();
    }
}